Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 4 - Commands / Command Definitions


Get AppleScript command, application command

The Get command can function as an AppleScript command or an application command. The AppleScript command returns the value of an expression.
The application command returns the value of an object. In both cases, the command assigns the value returned to the predefined variable result.

APPLESCRIPT COMMAND SYNTAX
[ get ] expression [ as className ]
APPLICATION COMMAND SYNTAX
[ get ] referenceToObject [ as className ]
PARAMETERS
expression
An expression whose value is to be returned in the
result variable.
Class: Any AppleScript expression
className
A class identifier that specifies the desired value class for
the returned data.
Class: Class
Default value: The default value class for the object or objects
referenceToObject

A reference to an object whose value is to be returned in the result variable.
Class: Reference
RESULT
The result is the value of the specified reference or expression.

If the referenceToObject parameter specifies a single object only (such as word 1 or the last word), the result is a single value. If the specified object doesn't exist, for example, if the reference is word 12 and there are fewer than 12 words in the specified container, no result is returned.

If the referenceToObject parameter refers to more than one object (such as the words whose first letter is "B"), the result is a list of values. The first item in the list is the value of the first object specified, the second item is the value of the second object specified, and so on. If the specified objects don't exist, for example, if the reference is the words whose first letter is "B" and there are no words that begin with "B", the result is an empty list.

Class: The class specified by the className parameter or a list of values of that class. If the application cannot return data in the value class specified by the className parameter, it returns a value or values of the default value class.

EXAMPLE
tell application "Scriptable Text Editor"   get paragraph 3 --gets the value
   copy result to item 2 of x --puts the result
end tell
NOTES
The word get in the Get command is optional because AppleScript automatically gets the value of expressions and references when they
appear in scripts.

For example, the following statements are equivalent:

item 1 of {"Hi,", "how", "are", "you?"}
get item 1 of {"Hi,", "how", "are", "you?"}
The following statements are also equivalent:

tell application "Scriptable Text Editor"   word 1 of document "Introduction"end tell
tell application "Scriptable Text Editor"   get word 1 of document "Introduction"end tell
ERROR
Error
number
Error message
-1728Can't get <reference>.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996